<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="订单编号" prop="orderNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderNumber"-->
<!--          placeholder="请输入订单编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="客户编号" prop="customerNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.customerNo"-->
<!--          placeholder="请输入客户编号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="客户名称" prop="customerName">-->
<!--        <el-input-->
<!--          v-model="queryParams.customerName"-->
<!--          placeholder="请输入客户名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="客户简称" prop="customerNickName">
        <el-input
          v-model="queryParams.customerNickName"
          placeholder="请输入客户简称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品类型" prop="productType">
        <el-input
          v-model="queryParams.productType"
          placeholder="请输入产品类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="料号" prop="materialNumber">
        <el-input
          v-model="queryParams.materialNumber"
          placeholder="请输入料号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单状态" prop="orderStatus">
        <el-select v-model="queryParams.orderStatus" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.cs_order_plan_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="模具号" prop="moldNumber">
        <el-input
          v-model="queryParams.moldNumber"
          placeholder="请输入模具号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单日期">
        <el-date-picker
          v-model="daterangeOrderDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="截止日期">
        <el-date-picker
          v-model="daterangeDeadlineDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="订单量" prop="orderQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderQuantity"-->
<!--          placeholder="请输入订单量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="已交付数量" prop="deliveredQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.deliveredQuantity"-->
<!--          placeholder="请输入已交付数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="成品库存" prop="finishedGoodsInventory">-->
<!--        <el-input-->
<!--          v-model="queryParams.finishedGoodsInventory"-->
<!--          placeholder="请输入成品库存"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="未包装数量" prop="unpackagedQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.unpackagedQuantity"-->
<!--          placeholder="请输入未包装数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="待产量" prop="pendingProduction">-->
<!--        <el-input-->
<!--          v-model="queryParams.pendingProduction"-->
<!--          placeholder="请输入待产量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="材料库存" prop="materialInventory">-->
<!--        <el-input-->
<!--          v-model="queryParams.materialInventory"-->
<!--          placeholder="请输入材料库存"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所需材料" prop="materialRequired">-->
<!--        <el-input-->
<!--          v-model="queryParams.materialRequired"-->
<!--          placeholder="请输入所需材料"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="包材" prop="packagingMaterial">-->
<!--        <el-input-->
<!--          v-model="queryParams.packagingMaterial"-->
<!--          placeholder="请输入包材"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="格数" prop="gridCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.gridCount"-->
<!--          placeholder="请输入格数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="删除标志" prop="delFlag">-->
<!--        <el-select v-model="queryParams.delFlag" placeholder="请选择删除标志" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.sys_delete_status"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建者" prop="createBy">-->
<!--        <el-input-->
<!--          v-model="queryParams.createBy"-->
<!--          placeholder="请输入创建者"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建时间">-->
<!--        <el-date-picker-->
<!--          v-model="daterangeCreateTime"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新者" prop="updateBy">-->
<!--        <el-input-->
<!--          v-model="queryParams.updateBy"-->
<!--          placeholder="请输入更新者"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="更新时间">-->
<!--        <el-date-picker-->
<!--          v-model="daterangeUpdateTime"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['customer:CsOrderPlan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['customer:CsOrderPlan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['customer:CsOrderPlan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['customer:CsOrderPlan:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['customer:CsOrderPlan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CsOrderPlanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
<!--      <el-table-column label="唯一主键ID" align="center" prop="id" />-->
<!--      <el-table-column label="订单编号" align="center" prop="orderNumber" />-->
<!--      <el-table-column label="客户编号" align="center" prop="customerNo" />-->
<!--      <el-table-column label="客户名称" align="center" prop="customerName" />-->
      <el-table-column label="客户简称" align="center" prop="customerNickName" />
      <el-table-column label="产品类型" align="center" prop="productType" />
      <el-table-column label="料号" align="center" prop="materialNumber" />
      <el-table-column label="订单状态" align="center" prop="orderStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cs_order_plan_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="模具号" align="center" prop="moldNumber" />
      <el-table-column label="下单日期" align="center" prop="orderDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="截止日期" align="center" prop="deadlineDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deadlineDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="订单量" align="center" prop="orderQuantity" />
      <el-table-column label="已交付数量" align="center" prop="deliveredQuantity" />
      <el-table-column label="成品库存" align="center" prop="finishedGoodsInventory" />
      <el-table-column label="未包装数量" align="center" prop="unpackagedQuantity" />
      <el-table-column label="待产量" align="center" prop="pendingProduction" />
      <el-table-column label="材料库存" align="center" prop="materialInventory" />
      <el-table-column label="材料规格" align="center" prop="materialSpecification" />
      <el-table-column label="所需材料" align="center" prop="materialRequired" />
      <el-table-column label="包材" align="center" prop="packagingMaterial" />
      <el-table-column label="格数" align="center" prop="gridCount" />
      <el-table-column label="拓展字段" align="center" prop="ext" />
      <el-table-column label="删除标志" align="center" prop="delFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_delete_status" :value="scope.row.delFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['customer:CsOrderPlan:query']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['customer:CsOrderPlan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['customer:CsOrderPlan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户订单计划对话框 -->
    <el-dialog :title="title" :visible.sync="updateopen" width="850px" append-to-body>
      <el-form :inline="true" class="demo-form-inline" ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="订单编号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="客户编号" prop="customerNo">
          <el-input v-model="form.customerNo" placeholder="请输入客户编号" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="客户简称" prop="customerNickName">
          <el-input v-model="form.customerNickName" placeholder="请输入客户简称" />
        </el-form-item>
        <el-form-item label="产品类型" prop="productType">
          <el-input v-model="form.productType" placeholder="请输入产品类型" />
        </el-form-item>
        <el-form-item label="料号" prop="materialNumber">
          <el-input v-model="form.materialNumber" placeholder="请输入料号" />
        </el-form-item>
        <el-form-item label="订单状态 (如:未开始/生产中/待包装/已完成/已延期)" prop="orderStatus">
          <el-select v-model="form.orderStatus" placeholder="请选择订单状态 (如:未开始/生产中/待包装/已完成/已延期)">
            <el-option
              v-for="dict in dict.type.cs_order_plan_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模具号" prop="moldNumber">
          <el-input v-model="form.moldNumber" placeholder="请输入模具号" />
        </el-form-item>
        <el-form-item label="下单日期" prop="orderDate">
          <el-date-picker clearable
                          v-model="form.orderDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择下单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="截止日期" prop="deadlineDate">
          <el-date-picker clearable
                          v-model="form.deadlineDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择截止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="订单量" prop="orderQuantity">
          <el-input v-model="form.orderQuantity" placeholder="请输入订单量" />
        </el-form-item>
        <el-form-item label="已交付数量" prop="deliveredQuantity">
          <el-input v-model="form.deliveredQuantity" placeholder="请输入已交付数量" />
        </el-form-item>
        <el-form-item label="成品库存" prop="finishedGoodsInventory">
          <el-input v-model="form.finishedGoodsInventory" placeholder="请输入成品库存" />
        </el-form-item>
        <el-form-item label="未包装数量" prop="unpackagedQuantity">
          <el-input v-model="form.unpackagedQuantity" placeholder="请输入未包装数量" />
        </el-form-item>
        <el-form-item label="待产量" prop="pendingProduction">
          <el-input v-model="form.pendingProduction" placeholder="请输入待产量" />
        </el-form-item>
        <el-form-item label="材料库存" prop="materialInventory">
          <el-input v-model="form.materialInventory" placeholder="请输入材料库存" />
        </el-form-item>
        <el-form-item label="材料规格" prop="materialSpecification">
          <el-input v-model="form.materialSpecification" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所需材料" prop="materialRequired">
          <el-input v-model="form.materialRequired" placeholder="请输入所需材料" />
        </el-form-item>
        <el-form-item label="包材" prop="packagingMaterial">
          <el-input v-model="form.packagingMaterial" placeholder="请输入包材" />
        </el-form-item>
        <el-form-item label="格数" prop="gridCount">
          <el-input v-model="form.gridCount" placeholder="请输入格数" />
        </el-form-item>
        <el-form-item label="拓展字段" prop="ext">
          <el-input v-model="form.ext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-select v-model="form.delFlag" placeholder="请选择删除标志">
            <el-option
              v-for="dict in dict.type.sys_delete_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 客户订单计划详情对话框 -->
    <el-dialog :title="title" :visible.sync="detailopen" width="850px" append-to-body>
      <el-form :inline="true" class="demo-form-inline" ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="订单编号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="客户编号" prop="customerNo">
          <el-input v-model="form.customerNo" placeholder="请输入客户编号" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="客户简称" prop="customerNickName">
          <el-input v-model="form.customerNickName" placeholder="请输入客户简称" />
        </el-form-item>
        <el-form-item label="产品类型" prop="productType">
          <el-input v-model="form.productType" placeholder="请输入产品类型" />
        </el-form-item>
        <el-form-item label="料号" prop="materialNumber">
          <el-input v-model="form.materialNumber" placeholder="请输入料号" />
        </el-form-item>
        <el-form-item label="订单状态 (如:未开始/生产中/待包装/已完成/已延期)" prop="orderStatus">
          <el-select v-model="form.orderStatus" placeholder="请选择订单状态 (如:未开始/生产中/待包装/已完成/已延期)">
            <el-option
              v-for="dict in dict.type.cs_order_plan_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="模具号" prop="moldNumber">
          <el-input v-model="form.moldNumber" placeholder="请输入模具号" />
        </el-form-item>
        <el-form-item label="下单日期" prop="orderDate">
          <el-date-picker clearable
                          v-model="form.orderDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择下单日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="截止日期" prop="deadlineDate">
          <el-date-picker clearable
                          v-model="form.deadlineDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择截止日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="订单量" prop="orderQuantity">
          <el-input v-model="form.orderQuantity" placeholder="请输入订单量" />
        </el-form-item>
        <el-form-item label="已交付数量" prop="deliveredQuantity">
          <el-input v-model="form.deliveredQuantity" placeholder="请输入已交付数量" />
        </el-form-item>
        <el-form-item label="成品库存" prop="finishedGoodsInventory">
          <el-input v-model="form.finishedGoodsInventory" placeholder="请输入成品库存" />
        </el-form-item>
        <el-form-item label="未包装数量" prop="unpackagedQuantity">
          <el-input v-model="form.unpackagedQuantity" placeholder="请输入未包装数量" />
        </el-form-item>
        <el-form-item label="待产量" prop="pendingProduction">
          <el-input v-model="form.pendingProduction" placeholder="请输入待产量" />
        </el-form-item>
        <el-form-item label="材料库存" prop="materialInventory">
          <el-input v-model="form.materialInventory" placeholder="请输入材料库存" />
        </el-form-item>
        <el-form-item label="材料规格" prop="materialSpecification">
          <el-input v-model="form.materialSpecification" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所需材料" prop="materialRequired">
          <el-input v-model="form.materialRequired" placeholder="请输入所需材料" />
        </el-form-item>
        <el-form-item label="包材" prop="packagingMaterial">
          <el-input v-model="form.packagingMaterial" placeholder="请输入包材" />
        </el-form-item>
        <el-form-item label="格数" prop="gridCount">
          <el-input v-model="form.gridCount" placeholder="请输入格数" />
        </el-form-item>
        <el-form-item label="拓展字段" prop="ext">
          <el-input v-model="form.ext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-select v-model="form.delFlag" placeholder="请选择删除标志">
            <el-option
              v-for="dict in dict.type.sys_delete_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailopen = false">关 闭</el-button>
      </div>
    </el-dialog>




    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import { listCsOrderPlan, getCsOrderPlan, delCsOrderPlan, addCsOrderPlan, updateCsOrderPlan } from "@/api/customer/CsOrderPlan";
import {getToken} from "@/utils/auth";

export default {
  name: "CsOrderPlan",
  dicts: ['sys_delete_status', 'cs_order_plan_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户订单计划表格数据
      CsOrderPlanList: [],
      // 弹出层标题
      title: "",
      // 是否详情显示弹出层
      detailopen: false
      ,
      // 是否修改新增显示弹出层
      updateopen: false
      ,
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeOrderDate: [],
      // 备注时间范围
      daterangeDeadlineDate: [],
      // 备注时间范围
      daterangeCreateTime: [],
      // 备注时间范围
      daterangeUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        customerNo: null,
        customerName: null,
        customerNickName: null,
        productType: null,
        materialNumber: null,
        orderStatus: null,
        moldNumber: null,
        orderDate: null,
        deadlineDate: null,
        projectName: null,
        orderQuantity: null,
        deliveredQuantity: null,
        finishedGoodsInventory: null,
        unpackagedQuantity: null,
        pendingProduction: null,
        materialInventory: null,
        materialSpecification: null,
        materialRequired: null,
        packagingMaterial: null,
        gridCount: null,
        ext: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      },
      // 表单参数
      form: {},
      // 导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题（
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "customer/CsOrderPlan/importData"
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询客户订单计划列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeOrderDate && '' != this.daterangeOrderDate) {
        this.queryParams.params["beginOrderDate"] = this.daterangeOrderDate[0];
        this.queryParams.params["endOrderDate"] = this.daterangeOrderDate[1];
      }
      if (null != this.daterangeDeadlineDate && '' != this.daterangeDeadlineDate) {
        this.queryParams.params["beginDeadlineDate"] = this.daterangeDeadlineDate[0];
        this.queryParams.params["endDeadlineDate"] = this.daterangeDeadlineDate[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
        this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
        this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
      }
      listCsOrderPlan(this.queryParams).then(response => {
        this.CsOrderPlanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.updateopen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        customerNo: null,
        customerName: null,
        customerNickName: null,
        productType: null,
        materialNumber: null,
        orderStatus: null,
        moldNumber: null,
        orderDate: null,
        deadlineDate: null,
        projectName: null,
        orderQuantity: null,
        deliveredQuantity: null,
        finishedGoodsInventory: null,
        unpackagedQuantity: null,
        pendingProduction: null,
        materialInventory: null,
        materialSpecification: null,
        materialRequired: null,
        packagingMaterial: null,
        gridCount: null,
        ext: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOrderDate = [];
      this.daterangeDeadlineDate = [];
      this.daterangeCreateTime = [];
      this.daterangeUpdateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.updateopen = true;
      this.title = "添加客户订单计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCsOrderPlan(id).then(response => {
        this.form = response.data;
        this.updateopen = true;
        this.title = "修改客户订单计划";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCsOrderPlan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.updateopen = false;
              this.getList();
            });
          } else {
            addCsOrderPlan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.updateopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除客户订单计划编号为"' + ids + '"的数据项？').then(function() {
        return delCsOrderPlan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 详情按钮操作 */
    handleView(row) {
      this.detailopen = true;
      this.form = row;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customer/CsOrderPlan/export', {
        ...this.queryParams
      }, `CsOrderPlan_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('customer/CsOrderPlan/importTemplate', {
      }, `customer_CsOrderPlan_template.xlsx`)
    },
// 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
// 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
// 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
